
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.analysis.bond_dissociation &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.bond_dissociation</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.analysis.bond_dissociation</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Module for BondDissociationEnergies.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">logging</span>

<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MSONable</span>

<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Molecule</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.graphs</span> <span class="kn">import</span> <span class="n">MoleculeGraph</span><span class="p">,</span> <span class="n">MolGraphSplitError</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.local_env</span> <span class="kn">import</span> <span class="n">OpenBabelNN</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.fragmenter</span> <span class="kn">import</span> <span class="n">open_ring</span>
<span class="kn">from</span> <span class="nn">pymatgen.io.babel</span> <span class="kn">import</span> <span class="n">BabelMolAdaptor</span>
<span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Samuel Blau&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2018, The Materials Project&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.0&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Samuel Blau&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;samblau1@gmail.com&quot;</span>
<span class="n">__status__</span> <span class="o">=</span> <span class="s2">&quot;Alpha&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;7/26/18&quot;</span>

<span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>


<div class="viewcode-block" id="BondDissociationEnergies"><a class="viewcode-back" href="../../../pymatgen.analysis.bond_dissociation.html#pymatgen.analysis.bond_dissociation.BondDissociationEnergies">[docs]</a><span class="k">class</span> <span class="nc">BondDissociationEnergies</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Standard constructor for bond dissociation energies. All bonds in the principle molecule are</span>
<span class="sd">    looped through and their dissociation energies are calculated given the energies of the resulting</span>
<span class="sd">    fragments, or, in the case of a ring bond, from the energy of the molecule obtained from breaking</span>
<span class="sd">    the bond and opening the ring. This class should only be called after the energies of the optimized</span>
<span class="sd">    principle molecule and all relevant optimized fragments have been determined, either from quantum</span>
<span class="sd">    chemistry or elsewhere. It was written to provide the analysis after running an Atomate fragmentation</span>
<span class="sd">    workflow.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">molecule_entry</span><span class="p">,</span> <span class="n">fragment_entries</span><span class="p">,</span> <span class="n">allow_additional_charge_separation</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">multibreak</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Note that the entries passed by the user must have the following keys: formula_pretty, initial_molecule,</span>
<span class="sd">        final_molecule. If a PCM is present, all entries should also have a pcm_dielectric key.</span>

<span class="sd">        Args:</span>
<span class="sd">            molecule_entry (dict): Entry for the principle molecule. Should have the keys mentioned above.</span>
<span class="sd">            fragment_entries (list of dicts): List of fragment entries. Each should have the keys mentioned above.</span>
<span class="sd">            allow_additional_charge_separation (bool): If True, consider larger than normal charge separation</span>
<span class="sd">                                                       among fragments. Defaults to False. See the definition</span>
<span class="sd">                                                       of self.expected_charges below for more specific information.</span>
<span class="sd">            multibreak (bool): If True, additionally attempt to break pairs of bonds. Defaults to False.</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">molecule_entry</span> <span class="o">=</span> <span class="n">molecule_entry</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filter_fragment_entries</span><span class="p">(</span><span class="n">fragment_entries</span><span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filtered_entries</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot; filtered entries&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bond_dissociation_energies</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">done_frag_pairs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">done_RO_frags</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ring_bonds</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="n">required_keys</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;formula_pretty&quot;</span><span class="p">,</span> <span class="s2">&quot;initial_molecule&quot;</span><span class="p">,</span> <span class="s2">&quot;final_molecule&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="s2">&quot;pcm_dielectric&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">molecule_entry</span><span class="p">:</span>
            <span class="n">required_keys</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;pcm_dielectric&quot;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">required_keys</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">molecule_entry</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="n">key</span> <span class="o">+</span> <span class="s2">&quot; must be present in molecule entry! Exiting...&quot;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">filtered_entries</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">entry</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="n">key</span> <span class="o">+</span> <span class="s2">&quot; must be present in all fragment entries! Exiting...&quot;</span><span class="p">)</span>

        <span class="c1"># Define expected charges</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">allow_additional_charge_separation</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">expected_charges</span> <span class="o">=</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">expected_charges</span> <span class="o">=</span> <span class="p">[</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">],</span>
                                         <span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">expected_charges</span> <span class="o">=</span> <span class="p">[</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span>
                                         <span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">expected_charges</span> <span class="o">=</span> <span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">expected_charges</span> <span class="o">=</span> <span class="p">[</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span>
                                         <span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">],</span>
                                         <span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span>
                                         <span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="mi">2</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">expected_charges</span> <span class="o">=</span> <span class="p">[</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">-</span> <span class="mi">2</span><span class="p">,</span>
                                         <span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span>
                                         <span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">],</span>
                                         <span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>

        <span class="c1"># Build principle molecule graph</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mol_graph</span> <span class="o">=</span> <span class="n">MoleculeGraph</span><span class="o">.</span><span class="n">with_local_env_strategy</span><span class="p">(</span><span class="n">Molecule</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">]),</span>
                                                               <span class="n">OpenBabelNN</span><span class="p">())</span>
        <span class="c1"># Loop through bonds, aka graph edges, and fragment and process:</span>
        <span class="k">for</span> <span class="n">bond</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">mol_graph</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">edges</span><span class="p">:</span>
            <span class="n">bonds</span> <span class="o">=</span> <span class="p">[(</span><span class="n">bond</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">bond</span><span class="p">[</span><span class="mi">1</span><span class="p">])]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fragment_and_process</span><span class="p">(</span><span class="n">bonds</span><span class="p">)</span>
        <span class="c1"># If mulitbreak, loop through pairs of ring bonds.</span>
        <span class="k">if</span> <span class="n">multibreak</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span>
                <span class="s2">&quot;Breaking pairs of ring bonds. WARNING: Structure changes much more likely, meaning dissociation values&quot;</span>
                <span class="s2">&quot; are less reliable! This is a bad idea!&quot;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bond_pairs</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">ii</span><span class="p">,</span> <span class="n">bond</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ring_bonds</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">jj</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ii</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ring_bonds</span><span class="p">)):</span>
                    <span class="n">bond_pair</span> <span class="o">=</span> <span class="p">[</span><span class="n">bond</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ring_bonds</span><span class="p">[</span><span class="n">jj</span><span class="p">]]</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">bond_pairs</span> <span class="o">+=</span> <span class="p">[</span><span class="n">bond_pair</span><span class="p">]</span>
            <span class="k">for</span> <span class="n">bond_pair</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_pairs</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">fragment_and_process</span><span class="p">(</span><span class="n">bond_pair</span><span class="p">)</span>

<div class="viewcode-block" id="BondDissociationEnergies.fragment_and_process"><a class="viewcode-back" href="../../../pymatgen.analysis.bond_dissociation.html#pymatgen.analysis.bond_dissociation.BondDissociationEnergies.fragment_and_process">[docs]</a>    <span class="k">def</span> <span class="nf">fragment_and_process</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bonds</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Fragment and process bonds.</span>

<span class="sd">        :param bonds: Bonds to process.</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Try to split the principle:</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">frags</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mol_graph</span><span class="o">.</span><span class="n">split_molecule_subgraphs</span><span class="p">(</span><span class="n">bonds</span><span class="p">,</span> <span class="n">allow_reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="n">frag_success</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="k">except</span> <span class="n">MolGraphSplitError</span><span class="p">:</span>
            <span class="c1"># If split is unsuccessful, then we have encountered a ring bond</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">bonds</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">ring_bonds</span> <span class="o">+=</span> <span class="n">bonds</span>
                <span class="c1"># So we open the ring and make sure we haven&#39;t already encountered an identically opened fragment:</span>
                <span class="n">RO_frag</span> <span class="o">=</span> <span class="n">open_ring</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mol_graph</span><span class="p">,</span> <span class="n">bonds</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span>
                <span class="n">frag_done</span> <span class="o">=</span> <span class="kc">False</span>
                <span class="k">for</span> <span class="n">done_RO_frag</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">done_RO_frags</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">RO_frag</span><span class="o">.</span><span class="n">isomorphic_to</span><span class="p">(</span><span class="n">done_RO_frag</span><span class="p">):</span>
                        <span class="n">frag_done</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">frag_done</span><span class="p">:</span>
                    <span class="c1"># If this is a new fragment, save the record and then search for relevant fragment entries:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">done_RO_frags</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">RO_frag</span><span class="p">)</span>
                    <span class="n">opened_entries</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">search_fragment_entries</span><span class="p">(</span><span class="n">RO_frag</span><span class="p">)</span>
                    <span class="n">good_entries</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="c1"># We will start by looking at entries with no structure change</span>
                    <span class="k">for</span> <span class="n">frag</span> <span class="ow">in</span> <span class="n">opened_entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>  <span class="c1"># 0 -&gt; no structural change</span>
                        <span class="c1"># Since a ring opening still yields a single molecule, it should have the same charge as the</span>
                        <span class="c1"># principle:</span>
                        <span class="k">if</span> <span class="n">frag</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]:</span>
                            <span class="n">good_entries</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">frag</span><span class="p">)</span>
                    <span class="c1"># If we didn&#39;t find any good entries, let&#39;s also look at those that exhibit structural changes:</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">good_entries</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="k">for</span> <span class="n">frag</span> <span class="ow">in</span> <span class="n">opened_entries</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>  <span class="c1"># 1 -&gt; YES structural change</span>
                            <span class="k">if</span> <span class="n">frag</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]:</span>
                                <span class="n">good_entries</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">frag</span><span class="p">)</span>
                    <span class="c1"># If we still have no good entries, something must have gone wrong with the calculations:</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">good_entries</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="n">bb</span> <span class="o">=</span> <span class="n">BabelMolAdaptor</span><span class="o">.</span><span class="n">from_molecule_graph</span><span class="p">(</span><span class="n">RO_frag</span><span class="p">)</span>
                        <span class="n">pbmol</span> <span class="o">=</span> <span class="n">bb</span><span class="o">.</span><span class="n">pybel_mol</span>
                        <span class="n">smiles</span> <span class="o">=</span> <span class="n">pbmol</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="s2">&quot;smi&quot;</span><span class="p">))</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
                        <span class="n">specie</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">get_node_attributes</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mol_graph</span><span class="o">.</span><span class="n">graph</span><span class="p">,</span> <span class="s2">&quot;specie&quot;</span><span class="p">)</span>
                        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Missing ring opening fragment resulting from the breakage of &quot;</span> <span class="o">+</span> <span class="n">specie</span><span class="p">[</span>
                            <span class="n">bonds</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]]</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">specie</span><span class="p">[</span><span class="n">bonds</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]]</span> <span class="o">+</span> <span class="s2">&quot; bond &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">bonds</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span>
                            <span class="n">bonds</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot; which would yield a molecule with this SMILES string: &quot;</span> <span class="o">+</span> <span class="n">smiles</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">good_entries</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                        <span class="c1"># If we have only one good entry, format it and addd it to the list that will eventually return:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">bond_dissociation_energies</span> <span class="o">+=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">build_new_entry</span><span class="p">(</span><span class="n">good_entries</span><span class="p">,</span> <span class="n">bonds</span><span class="p">)]</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="c1"># We shouldn&#39;t ever encounter more than one good entry.</span>
                        <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;There should only be one valid ring opening fragment! Exiting...&quot;</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">bonds</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Should only be trying to break two bonds if multibreak is true! Exiting...&quot;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;No reason to try and break more than two bonds at once! Exiting...&#39;</span><span class="p">)</span>
                <span class="k">raise</span> <span class="ne">ValueError</span>
            <span class="n">frag_success</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="n">frag_success</span><span class="p">:</span>
            <span class="c1"># If the principle did successfully split, then we aren&#39;t dealing with a ring bond.</span>
            <span class="c1"># As above, we begin by making sure we haven&#39;t already encountered an identical pair of fragments:</span>
            <span class="n">frags_done</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="k">for</span> <span class="n">frag_pair</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">done_frag_pairs</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">frag_pair</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">isomorphic_to</span><span class="p">(</span><span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
                    <span class="k">if</span> <span class="n">frag_pair</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">isomorphic_to</span><span class="p">(</span><span class="n">frags</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span>
                        <span class="n">frags_done</span> <span class="o">=</span> <span class="kc">True</span>
                        <span class="k">break</span>
                <span class="k">elif</span> <span class="n">frag_pair</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">isomorphic_to</span><span class="p">(</span><span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
                    <span class="k">if</span> <span class="n">frag_pair</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">isomorphic_to</span><span class="p">(</span><span class="n">frags</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span>
                        <span class="n">frags_done</span> <span class="o">=</span> <span class="kc">True</span>
                        <span class="k">break</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">frags_done</span><span class="p">:</span>
                <span class="c1"># If we haven&#39;t, we save this pair and search for the relevant fragment entries:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">done_frag_pairs</span> <span class="o">+=</span> <span class="p">[</span><span class="n">frags</span><span class="p">]</span>
                <span class="n">num_entries_for_this_frag_pair</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="n">frag1_entries</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">search_fragment_entries</span><span class="p">(</span><span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">frag2_entries</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">search_fragment_entries</span><span class="p">(</span><span class="n">frags</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="n">frag1_charges_found</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">frag2_charges_found</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="c1"># We then check for our expected charges of each fragment:</span>
                <span class="k">for</span> <span class="n">frag1</span> <span class="ow">in</span> <span class="n">frag1_entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">frag1_entries</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
                    <span class="k">if</span> <span class="n">frag1</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">frag1_charges_found</span><span class="p">:</span>
                        <span class="n">frag1_charges_found</span> <span class="o">+=</span> <span class="p">[</span><span class="n">frag1</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]]</span>
                <span class="k">for</span> <span class="n">frag2</span> <span class="ow">in</span> <span class="n">frag2_entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">frag2_entries</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
                    <span class="k">if</span> <span class="n">frag2</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">frag2_charges_found</span><span class="p">:</span>
                        <span class="n">frag2_charges_found</span> <span class="o">+=</span> <span class="p">[</span><span class="n">frag2</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]]</span>
                <span class="c1"># If we&#39;re missing some of either, tell the user:</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">frag1_charges_found</span><span class="p">)</span> <span class="o">&lt;</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expected_charges</span><span class="p">):</span>
                    <span class="n">bb</span> <span class="o">=</span> <span class="n">BabelMolAdaptor</span><span class="p">(</span><span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">molecule</span><span class="p">)</span>
                    <span class="n">pbmol</span> <span class="o">=</span> <span class="n">bb</span><span class="o">.</span><span class="n">pybel_mol</span>
                    <span class="n">smiles</span> <span class="o">=</span> <span class="n">pbmol</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="s2">&quot;smi&quot;</span><span class="p">))</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="k">for</span> <span class="n">charge</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">expected_charges</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">charge</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">frag1_charges_found</span><span class="p">:</span>
                            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Missing charge &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">charge</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; for fragment &quot;</span> <span class="o">+</span> <span class="n">smiles</span><span class="p">)</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">frag2_charges_found</span><span class="p">)</span> <span class="o">&lt;</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expected_charges</span><span class="p">):</span>
                    <span class="n">bb</span> <span class="o">=</span> <span class="n">BabelMolAdaptor</span><span class="p">(</span><span class="n">frags</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">molecule</span><span class="p">)</span>
                    <span class="n">pbmol</span> <span class="o">=</span> <span class="n">bb</span><span class="o">.</span><span class="n">pybel_mol</span>
                    <span class="n">smiles</span> <span class="o">=</span> <span class="n">pbmol</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="s2">&quot;smi&quot;</span><span class="p">))</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="k">for</span> <span class="n">charge</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">expected_charges</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">charge</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">frag2_charges_found</span><span class="p">:</span>
                            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Missing charge &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">charge</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; for fragment &quot;</span> <span class="o">+</span> <span class="n">smiles</span><span class="p">)</span>
                <span class="c1"># Now we attempt to pair fragments with the right total charge, starting with only fragments with no</span>
                <span class="c1"># structural change:</span>
                <span class="k">for</span> <span class="n">frag1</span> <span class="ow">in</span> <span class="n">frag1_entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>  <span class="c1"># 0 -&gt; no structural change</span>
                    <span class="k">for</span> <span class="n">frag2</span> <span class="ow">in</span> <span class="n">frag2_entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>  <span class="c1"># 0 -&gt; no structural change</span>
                        <span class="k">if</span> <span class="n">frag1</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">frag2</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">==</span> \
                                <span class="bp">self</span><span class="o">.</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">bond_dissociation_energies</span> <span class="o">+=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">build_new_entry</span><span class="p">([</span><span class="n">frag1</span><span class="p">,</span> <span class="n">frag2</span><span class="p">],</span> <span class="n">bonds</span><span class="p">)]</span>
                            <span class="n">num_entries_for_this_frag_pair</span> <span class="o">+=</span> <span class="mi">1</span>
                <span class="c1"># If we haven&#39;t found the number of fragment pairs that we expect, we expand our search to include</span>
                <span class="c1"># fragments that do exhibit structural change:</span>
                <span class="k">if</span> <span class="n">num_entries_for_this_frag_pair</span> <span class="o">&lt;</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expected_charges</span><span class="p">):</span>
                    <span class="k">for</span> <span class="n">frag1</span> <span class="ow">in</span> <span class="n">frag1_entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>  <span class="c1"># 0 -&gt; no structural change</span>
                        <span class="k">for</span> <span class="n">frag2</span> <span class="ow">in</span> <span class="n">frag2_entries</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>  <span class="c1"># 1 -&gt; YES structural change</span>
                            <span class="k">if</span> <span class="n">frag1</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">frag2</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">==</span> \
                                    <span class="bp">self</span><span class="o">.</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]:</span>
                                <span class="bp">self</span><span class="o">.</span><span class="n">bond_dissociation_energies</span> <span class="o">+=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">build_new_entry</span><span class="p">([</span><span class="n">frag1</span><span class="p">,</span> <span class="n">frag2</span><span class="p">],</span> <span class="n">bonds</span><span class="p">)]</span>
                                <span class="n">num_entries_for_this_frag_pair</span> <span class="o">+=</span> <span class="mi">1</span>
                    <span class="k">for</span> <span class="n">frag1</span> <span class="ow">in</span> <span class="n">frag1_entries</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>  <span class="c1"># 1 -&gt; YES structural change</span>
                        <span class="k">for</span> <span class="n">frag2</span> <span class="ow">in</span> <span class="n">frag2_entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>  <span class="c1"># 0 -&gt; no structural change</span>
                            <span class="k">if</span> <span class="n">frag1</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">frag2</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">==</span> \
                                    <span class="bp">self</span><span class="o">.</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]:</span>
                                <span class="bp">self</span><span class="o">.</span><span class="n">bond_dissociation_energies</span> <span class="o">+=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">build_new_entry</span><span class="p">([</span><span class="n">frag1</span><span class="p">,</span> <span class="n">frag2</span><span class="p">],</span> <span class="n">bonds</span><span class="p">)]</span>
                                <span class="n">num_entries_for_this_frag_pair</span> <span class="o">+=</span> <span class="mi">1</span></div>

<div class="viewcode-block" id="BondDissociationEnergies.search_fragment_entries"><a class="viewcode-back" href="../../../pymatgen.analysis.bond_dissociation.html#pymatgen.analysis.bond_dissociation.BondDissociationEnergies.search_fragment_entries">[docs]</a>    <span class="k">def</span> <span class="nf">search_fragment_entries</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">frag</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Search all fragment entries for those isomorphic to the given fragment.</span>
<span class="sd">        We distinguish between entries where both initial and final molgraphs are isomorphic to the</span>
<span class="sd">        given fragment (entries) vs those where only the intial molgraph is isomorphic to the given</span>
<span class="sd">        fragment (initial_entries) vs those where only the final molgraph is isomorphic (final_entries)</span>

<span class="sd">        Args:</span>
<span class="sd">            frag: Fragment</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">entries</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">initial_entries</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">final_entries</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">filtered_entries</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">frag</span><span class="o">.</span><span class="n">isomorphic_to</span><span class="p">(</span><span class="n">entry</span><span class="p">[</span><span class="s2">&quot;initial_molgraph&quot;</span><span class="p">])</span> <span class="ow">and</span> <span class="n">frag</span><span class="o">.</span><span class="n">isomorphic_to</span><span class="p">(</span><span class="n">entry</span><span class="p">[</span><span class="s2">&quot;final_molgraph&quot;</span><span class="p">]):</span>
                <span class="n">entries</span> <span class="o">+=</span> <span class="p">[</span><span class="n">entry</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">frag</span><span class="o">.</span><span class="n">isomorphic_to</span><span class="p">(</span><span class="n">entry</span><span class="p">[</span><span class="s2">&quot;initial_molgraph&quot;</span><span class="p">]):</span>
                <span class="n">initial_entries</span> <span class="o">+=</span> <span class="p">[</span><span class="n">entry</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">frag</span><span class="o">.</span><span class="n">isomorphic_to</span><span class="p">(</span><span class="n">entry</span><span class="p">[</span><span class="s2">&quot;final_molgraph&quot;</span><span class="p">]):</span>
                <span class="n">final_entries</span> <span class="o">+=</span> <span class="p">[</span><span class="n">entry</span><span class="p">]</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">entries</span><span class="p">,</span> <span class="n">initial_entries</span><span class="p">,</span> <span class="n">final_entries</span><span class="p">]</span></div>

<div class="viewcode-block" id="BondDissociationEnergies.filter_fragment_entries"><a class="viewcode-back" href="../../../pymatgen.analysis.bond_dissociation.html#pymatgen.analysis.bond_dissociation.BondDissociationEnergies.filter_fragment_entries">[docs]</a>    <span class="k">def</span> <span class="nf">filter_fragment_entries</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fragment_entries</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Filter the fragment entries.</span>

<span class="sd">        :param fragment_entries:</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filtered_entries</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="n">fragment_entries</span><span class="p">:</span>
            <span class="c1"># Check and make sure that PCM dielectric is consistent with principle:</span>
            <span class="k">if</span> <span class="s2">&quot;pcm_dielectric&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">molecule_entry</span><span class="p">:</span>
                <span class="k">if</span> <span class="s2">&quot;pcm_dielectric&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">entry</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Principle molecule has a PCM dielectric of &quot;</span> <span class="o">+</span>
                                       <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;pcm_dielectric&quot;</span><span class="p">])</span> <span class="o">+</span>
                                       <span class="s2">&quot; but a fragment entry has no PCM dielectric! Please only pass fragment entries&quot;</span>
                                       <span class="s2">&quot; with PCM details consistent with the principle entry. Exiting...&quot;</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;pcm_dielectric&quot;</span><span class="p">]</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;pcm_dielectric&quot;</span><span class="p">]:</span>
                    <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Principle molecule has a PCM dielectric of &quot;</span> <span class="o">+</span>
                                       <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;pcm_dielectric&quot;</span><span class="p">])</span> <span class="o">+</span>
                                       <span class="s2">&quot; but a fragment entry has a different PCM dielectric! Please only pass&quot;</span>
                                       <span class="s2">&quot; fragment entries with PCM details consistent with the principle entry.&quot;</span>
                                       <span class="s2">&quot; Exiting...&quot;</span><span class="p">)</span>
            <span class="c1"># Build initial and final molgraphs:</span>
            <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;initial_molgraph&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">MoleculeGraph</span><span class="o">.</span><span class="n">with_local_env_strategy</span><span class="p">(</span>
                <span class="n">Molecule</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">entry</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">]),</span>
                <span class="n">OpenBabelNN</span><span class="p">())</span>
            <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;final_molgraph&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">MoleculeGraph</span><span class="o">.</span><span class="n">with_local_env_strategy</span><span class="p">(</span><span class="n">Molecule</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">entry</span><span class="p">[</span><span class="s2">&quot;final_molecule&quot;</span><span class="p">]),</span>
                                                                            <span class="n">OpenBabelNN</span><span class="p">())</span>
            <span class="c1"># Classify any potential structural change that occured during optimization:</span>
            <span class="k">if</span> <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;initial_molgraph&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">isomorphic_to</span><span class="p">(</span><span class="n">entry</span><span class="p">[</span><span class="s2">&quot;final_molgraph&quot;</span><span class="p">]):</span>
                <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;structure_change&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;no_change&quot;</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">initial_graph</span> <span class="o">=</span> <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;initial_molgraph&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">graph</span>
                <span class="n">final_graph</span> <span class="o">=</span> <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;final_molgraph&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">graph</span>
                <span class="k">if</span> <span class="n">nx</span><span class="o">.</span><span class="n">is_connected</span><span class="p">(</span><span class="n">initial_graph</span><span class="o">.</span><span class="n">to_undirected</span><span class="p">())</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">nx</span><span class="o">.</span><span class="n">is_connected</span><span class="p">(</span><span class="n">final_graph</span><span class="o">.</span><span class="n">to_undirected</span><span class="p">()):</span>
                    <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;structure_change&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;unconnected_fragments&quot;</span>
                <span class="k">elif</span> <span class="n">final_graph</span><span class="o">.</span><span class="n">number_of_edges</span><span class="p">()</span> <span class="o">&lt;</span> <span class="n">initial_graph</span><span class="o">.</span><span class="n">number_of_edges</span><span class="p">():</span>
                    <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;structure_change&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;fewer_bonds&quot;</span>
                <span class="k">elif</span> <span class="n">final_graph</span><span class="o">.</span><span class="n">number_of_edges</span><span class="p">()</span> <span class="o">&gt;</span> <span class="n">initial_graph</span><span class="o">.</span><span class="n">number_of_edges</span><span class="p">():</span>
                    <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;structure_change&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;more_bonds&quot;</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;structure_change&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;bond_change&quot;</span>
            <span class="n">found_similar_entry</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="c1"># Check for uniqueness</span>
            <span class="k">for</span> <span class="n">ii</span><span class="p">,</span> <span class="n">filtered_entry</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filtered_entries</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">filtered_entry</span><span class="p">[</span><span class="s2">&quot;formula_pretty&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;formula_pretty&quot;</span><span class="p">]:</span>
                    <span class="k">if</span> <span class="n">filtered_entry</span><span class="p">[</span><span class="s2">&quot;initial_molgraph&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">isomorphic_to</span><span class="p">(</span><span class="n">entry</span><span class="p">[</span><span class="s2">&quot;initial_molgraph&quot;</span><span class="p">])</span> <span class="ow">and</span> \
                            <span class="n">filtered_entry</span><span class="p">[</span><span class="s2">&quot;final_molgraph&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">isomorphic_to</span><span class="p">(</span><span class="n">entry</span><span class="p">[</span><span class="s2">&quot;final_molgraph&quot;</span><span class="p">])</span> <span class="ow">and</span> \
                            <span class="n">filtered_entry</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">]:</span>
                        <span class="n">found_similar_entry</span> <span class="o">=</span> <span class="kc">True</span>
                        <span class="c1"># If two entries are found that pass the above similarity check, take the one with the lower</span>
                        <span class="c1"># energy:</span>
                        <span class="k">if</span> <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;final_energy&quot;</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">filtered_entry</span><span class="p">[</span><span class="s2">&quot;final_energy&quot;</span><span class="p">]:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">filtered_entries</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span> <span class="o">=</span> <span class="n">entry</span>
                        <span class="c1"># Note that this will essentially choose between singlet and triplet entries assuming both have</span>
                        <span class="c1"># the same structural details</span>
                        <span class="k">break</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">found_similar_entry</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">filtered_entries</span> <span class="o">+=</span> <span class="p">[</span><span class="n">entry</span><span class="p">]</span></div>

<div class="viewcode-block" id="BondDissociationEnergies.build_new_entry"><a class="viewcode-back" href="../../../pymatgen.analysis.bond_dissociation.html#pymatgen.analysis.bond_dissociation.BondDissociationEnergies.build_new_entry">[docs]</a>    <span class="k">def</span> <span class="nf">build_new_entry</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">frags</span><span class="p">,</span> <span class="n">bonds</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Simple function to format a bond dissociation entry that will eventually be returned to the user.</span>

<span class="sd">        :param frags:</span>
<span class="sd">        :param bonds:</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">specie</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">get_node_attributes</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mol_graph</span><span class="o">.</span><span class="n">graph</span><span class="p">,</span> <span class="s2">&quot;specie&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">frags</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">new_entry</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_energy&quot;</span><span class="p">]</span> <span class="o">-</span> <span class="p">(</span><span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;final_energy&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">frags</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;final_energy&quot;</span><span class="p">]),</span>
                         <span class="n">bonds</span><span class="p">,</span> <span class="n">specie</span><span class="p">[</span><span class="n">bonds</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]],</span> <span class="n">specie</span><span class="p">[</span><span class="n">bonds</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]],</span> <span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;smiles&quot;</span><span class="p">],</span>
                         <span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;structure_change&quot;</span><span class="p">],</span> <span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">],</span>
                         <span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;spin_multiplicity&quot;</span><span class="p">],</span> <span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;final_energy&quot;</span><span class="p">],</span>
                         <span class="n">frags</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;smiles&quot;</span><span class="p">],</span> <span class="n">frags</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;structure_change&quot;</span><span class="p">],</span> <span class="n">frags</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">],</span>
                         <span class="n">frags</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;spin_multiplicity&quot;</span><span class="p">],</span> <span class="n">frags</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;final_energy&quot;</span><span class="p">]]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">new_entry</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">molecule_entry</span><span class="p">[</span><span class="s2">&quot;final_energy&quot;</span><span class="p">]</span> <span class="o">-</span> <span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;final_energy&quot;</span><span class="p">],</span> <span class="n">bonds</span><span class="p">,</span> <span class="n">specie</span><span class="p">[</span><span class="n">bonds</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]],</span>
                         <span class="n">specie</span><span class="p">[</span><span class="n">bonds</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]],</span> <span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;smiles&quot;</span><span class="p">],</span> <span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;structure_change&quot;</span><span class="p">],</span>
                         <span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;charge&quot;</span><span class="p">],</span> <span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;initial_molecule&quot;</span><span class="p">][</span><span class="s2">&quot;spin_multiplicity&quot;</span><span class="p">],</span>
                         <span class="n">frags</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;final_energy&quot;</span><span class="p">]]</span>
        <span class="k">return</span> <span class="n">new_entry</span></div></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.bond_dissociation</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>